<template>
  <!--主修专业确认管理-日期控件-年级（显示当前学年）-->
  <div>
    <el-date-picker class="dateclass" :disabled="disabled" clearable v-model="value" value-format="yyyy" type="year" :default-value="defaultGrade" :placeholder="$t('interScoreEntry.pleaseSelect')" @change="handleGradeChange">
    </el-date-picker>
  </div>
</template>
<script>
import Api from "common/src/api/calendars";
export default {
  name: 'eduDatePicker',
  model: {
    prop: 'currentValue', //绑定prop传递的值
    event: 'change' //事件名称
  },
  props: {
    currentValue: { type: String, default: "" },
    disabled: { type: Boolean, default: false },
    defaultGrade: { type: String, default: "" } //预留可设置默认学年
  },
  data() {
    return {
      value: this.currentValue //关联父组件的值
    };
  },
  watch: {
    currentValue: {
      handler: function (newVal) {
        this.value = newVal; // 便于清空父组件的值
      },
      deep: true
    }
  },
  created() {
    this.getDefaultGrade();
  },
  methods: {
    //查询当前年级
    getDefaultGrade() {
      Api.currentTermCalendar().then(res => {
        this.defaultGrade = res.data.schoolCalendar.year.toString();
      });
    },
    handleGradeChange(val) {
      this.value = val;
      this.$emit('change', val);
    }
  }
};
</script>
<style lang="scss" scoped>
.dateclass {
  width: 100%;
}
</style>
